﻿using LuaInterface;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LUALearn4 : MonoBehaviour
{
    public string luaResourcePath;
    LuaState mLuaState;
    LuaLooper mLuaLooper;


    void Awake()
    {
        DelegateFactory.Init();//初始化各种委托

        mLuaState = new LuaState();
        mLuaState.Start();
        LuaBinder.Bind(mLuaState);//把各种unity的接口绑定进LUA.

        var sw = new System.Diagnostics.Stopwatch();
        sw.Start();

        mLuaLooper = gameObject.AddComponent<LuaLooper>();
        mLuaLooper.luaState = mLuaState;

        var textAsset = Resources.Load<TextAsset>(luaResourcePath);
        mLuaState.DoString(textAsset.text, "LUALearn4.cs");
        mLuaState.Invoke<object>("Foo", false);

        sw.Stop();

        Debug.Log("ms: " + sw.ElapsedMilliseconds);
    }

    void OnDestroy()
    {
        mLuaLooper.Destroy();
        mLuaState.Dispose();
    }
}
